/**
 * @file contff_bt_builder_test.cpp
 * @brief A test file for a contingent-ff plan to a behavior tree.
 * @date 2024-02-29
*/

#include <iostream>
#include <string>
#include <memory>
#include <filesystem>

#include "contbtsys_bt_builder/ContBTBuilder.hpp"
#include "cont_ff_plan_solver/cont_ff_plan_solver.hpp"

int main(int argc, char** argv) {
    ContBTSys::ContFFPlanSolver solver;
    ContBTSys::ContBTBuilder builder(std::make_shared<ContBTSys::ContFFPlanSolver>(solver));
    std::string bt = "";

    // No pddl files input, use default test cases
    if (argc <= 1) {
        // get current directory path
        std::filesystem::path cur_dir = std::filesystem::current_path();

        // get the path of the domain and problem files
        std::string test_domain = cur_dir.string() + "/tests/blocks/domain.pddl";
        std::string test_problem = cur_dir.string() + "/tests/blocks/p3.pddl";

        std::cout << "Using default test domain file: " << test_domain << std::endl;
        std::cout << "Using default test problem file: " << test_problem << std::endl;

        // get the behavior tree
        bt = builder.getBT(test_domain, test_problem);
    } else {
        // get the plan tree
        
        std::cout << "Domain file: " << argv[1] << std::endl;
        std::cout << "Problem file: " << argv[2] << std::endl;

        bt = builder.getBT(argv[1], argv[2]);
    }
    
    // print the behavior tree
    if (bt != "") {
        std::cout << "Got a feasible plan, below are the generated behavior tree: " << std::endl;
        std::cout << " ===================================== " << std::endl;
        std::cout << bt << std::endl;
        std::cout << " ===================================== " << std::endl;
    } else {
        std::cout << "No plan found!" << std::endl;
    }

    return 0;
}
